#
#
CLEANFILES = dummyref.c symbols_local.txt *~
DISTCLEANFILES = *~

clx_includedir = @prefix@/include/clx

if ECM_DEBUG
BFD = -lbfd @BFD_DEP_LIBS@
endif

EDBD_LIBS = @LIBS@
LIBS =

INCLUDES = -I../../lib/libbase -I../../lib/libsr -I../../lib/libebc -I../../lib/libedb -I../../lib/libeds

noinst_PROGRAMS = edbd_my edbd_my_sym edbd_linked
bin_PROGRAMS = edbd keygen

edbd_SOURCES =
edbd_DEPENDENCIES = edbd_linked
edbd_LINK = objcopy --keep-global-symbols=symbols.txt edbd_linked edbd

edbd_linked_SOURCES = 
edbd_linked_LDFLAGS = -dlopen self
edbd_linked_LDADD = edbd_my_sym -lm @LINK_DL@ -lpthread $(BFD) $(EDBD_LIBS)
edbd_linked_DEPENDENCIES = edbd_my_sym

edbd_my_sym_SOURCES =

edbd_my_sym_LINK = objcopy --localize-symbols=symbols_local.txt edbd_my edbd_my_sym; objcopy --redefine-syms=symbols_redef.txt edbd_my_sym
edbd_my_sym_DEPENDENCIES = edbd_my symbols_local.txt symbols_redef.txt

edbd_my_SOURCES = edbd.c edbd_cmd.c edbd_ic.c edbd_init.c \
		edbd_elect.c edbd_snapshot.c edbd_auth.c traverse.c \
		edbd_update.c edbd_log.c edbd_conn.c edbd_util.c license.c \
		reactor.c edbd_xe.c edbd_mod.c edbd_resolve.c autoreactor.c \
		edbsr.c edbsr.h \
		edbroot.c edbroot.h edbroot_set.c edbroot_ref.c \
		ecxroot.c ecxroot.h ecxroot_set.c ecxroot_op.h \
		edbd_basefunc.c bdexpr.c lnpsensor.c extcall.c treelock.c \
		edbd_walk.c bdexpr_exec.c edbd_file.c edbd_exec.c \
		bdexpr_CS.c ecx_dom.c ecx_attr.c ecx_esc.c ecx_mod.c \
		ctxproc.c ecx_err.c encdec.c \
		edbd_dbg.c edbd_sr.c edbd_sr.h \
		edbd_redef_ebc.c \
		edbd_vsr.c edbd_vsr.h edbd_vsr_set.c \
		edbd.h license.h reactor.h \
		bdexpr.h edbd_log.h edbd_conn.h \
		edbd_ecx.h ecx_esc.h

nodist_edbd_my_SOURCES = dummyref.c

edbd_my_LDADD = ../../lib/libeds/.libs/libeds.a \
	../../lib/libedb/.libs/libedb.a \
	../../lib/libebc/.libs/libebc.a \
	../../lib/libsr/.libs/libsr.a \
	../../lib/libbase/.libs/libbase.a

edbd_my_LINK = $(LD) -r -o $@
edbd_my_DEPENDENCIES = ../../lib/libeds/.libs/libeds.a \
	../../lib/libedb/.libs/libedb.a \
	../../lib/libebc/.libs/libebc.a \
	../../lib/libsr/.libs/libsr.a \
	../../lib/libbase/.libs/libbase.a

dummyref.c: symbols.txt
	$(AWK) 'NF > 0 && !/^main/ { print "extern int " $$1 ";" }' symbols.txt > $@

symbols_local.txt: symbols_redef.txt
	$(AWK) 'BEGIN { print "# This file is generated automatically from symbols_redef.txt"; } NF > 0 && /^[^#]/ { print $$2 }' $< > $@

clx_include_HEADERS = edbd_extcall.h

keygen_SOURCES = keygen.c license.c encdec.c
keygen_CFLAGS = -DKEYGEN
keygen_LDADD = ../../lib/libbase/libbase.la @LINK_DL@ -lpthread

install-exec-hook:
	$(INSTALL) -d @prefix@/clx/modules

EXTRA_DIST = symbols.txt symbols_redef.txt
